﻿#region License

// // -------------------------------------------------------------------------------------
// // This information refers to SecurityHandler.cs
// // 
// // Copyright 2012 ELEN7046 Group 2
// // 
// // Last Modified on: 2012-06-10
// // 
// // Contributors:
// // 
// // Amith Sewnarain
// // Elmar Vosloo
// // Jason Thorne
// // Satish Jewan
// // 
// // Wits University 
// // School of Electrical & Information Engineering
// // Software Engineering Tools and Techniques
// // 
// // -------------------------------------------------------------------------------------
// // 
// // This file (SecurityHandler.cs) is part of the DishDash Event Visualization System.
// // 
// // DishDash is free software: you can redistribute it and/or modify
// // it under the terms of the GNU General Public License as published by
// // the Free Software Foundation, either version 3 of the License, or
// // (at your option) any later version.
// // 
// // DishDash is distributed in the hope that it will be useful,
// // but WITHOUT ANY WARRANTY; without even the implied warranty of
// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// // GNU General Public License for more details.
// // 
// // You should have received a copy of the GNU General Public License
// // along with DishDash.  
// // If not, see <http://www.gnu.org/licenses/>.
// // -------------------------------------------------------------------------------------

#endregion

#region Using Directives

using Custom.Web.Extensions;
using ProfilingApp.Handlers.Messages;
//using MessageAPI.Core.Implementation;

#endregion

//using MessageAPI;

namespace ProfilingApp.Handlers
{
    public class SecurityHandler : MethodRoutingJsonHandler
    {
        //private long startTime;

        public LoginResponse Login(LoginRequest request)
        {
            //Start Time for performance event
            //StartTimer();
            var client = new SecurityService.SecurityProviderClient();

            var authResponse = client.Authenticate(request.UserName, request.Password);

            //Create context values for performance event
            //Dictionary<string, string> contexts = new Dictionary<string, string>();
            //contexts.Add("UserName", request.UserName);

            //Log the event
            //LogEvent("ProfilingApp.Handlers.SecurityHandler.LoginResponse", contexts);

            return new LoginResponse {IsAuthenticated = authResponse};
        }


        //private void StartTimer()
        //{
        //    startTime = DateTime.Now.Ticks;
        //}

        /// <summary>
        /// Log the a peformance event using the MessageAPI. Also stops the timer and resets it.
        /// </summary>
        /// <param name="EventDesc">The namespace and method name</param>
        /// <param name="contextvalues">The context values of the performance event</param>
        //private void LogEvent(string EventDesc, Dictionary<string, string> contextvalues)
        //{
        //    long stopTime = DateTime.Now.Ticks;
        //    long duration = (stopTime - startTime) / 10000;
        //    startTime = 0;

        //    IPerformanceInstrumentationServiceFactory performanceInstrumentationServiceFactory = new PerformanceInstrumentationServiceFactory();
        //    IPerformanceInstrumentationService performanceInstrumentationService = performanceInstrumentationServiceFactory.GetPerformanceInstrumentationService();

        //    PerformanceEvent performanceEvent = new PerformanceEvent()
        //    {
        //        Category = EventDesc,
        //        TimeStamp = DateTime.Now.Ticks,
        //        Value = duration,
        //        ContextValues = contextvalues
        //    };

        //    performanceInstrumentationService.SendEvent(performanceEvent);
        //}
    }
}